<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script id="jq" async src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script>
        var jq = document.querySelector('#jq');
        jq.addEventListener('load', function () {
            $(function ($) {
                var URL = window.URL || window.webkitURL;
                var file = $('<input>', {type: 'file'});
//                URL.createObjectURL()
                file.on('change', function () {
                    if (this.files.length > 0) {

                        var fr = new FileReader();
                        fr.addEventListener('load', function () {
                            $('textarea').text(this.result);
                        });
                        fr.readAsText(this.files[0])
//                        fr.readAsDataURL(this.files[0])
//                        fr.readAsBinaryString(this.files[0])

                    }
                });

                file.appendTo('body');

                $('button').click(function () {
                    var str = $('textarea').text();
                    if (str.trim() === '') return;
                    var blob = stringToBlob(str);

                    download(blob, 'index.html')
                })
            })
        })
    </script>
</head>
<body>
<textarea rows="40" cols="150"></textarea>
<button>download</button>
<script>
    function download(href, title) {
        var a = document.createElement('a');
        a.setAttribute('href', href);
        a.setAttribute('download', title);
        a.click();
    }


    function stringToBlob(str) {
        var content = str;
        if (content === '') {
            return false
        }
        var blob = new Blob([content], {type: 'text/plain'});
        return href = URL.createObjectURL(blob)
    }
</script>
</body>
</html>